package com.lcxedu.notebook.controller;

import com.lcxedu.notebook.entity.User;
import com.lcxedu.notebook.service.UserMapperService;
import com.lcxedu.notebook.utils.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Title: UserController
 * @Author: 李晨曦
 * @Date: 2025/6/11
 * 好好看 好好学 都能学会 都能学好
 * 我亦无他 唯手熟尔
 */
@Controller
public class UserController {

    @Resource
    private UserMapperService userMapperService;

    @PostMapping("/register")
    @ResponseBody
    public Result register(@RequestBody User user) {
        System.out.println(user);
        int i = userMapperService.insertSelective(user);
        if (i > 0) {
            return Result.success();
        }
        return Result.error("400","注册失败");
    }

    @RequestMapping("/login")
    @ResponseBody
    public Result login(@RequestParam String username, @RequestParam String password) {
        System.out.println(username + password);
        User user = userMapperService.selectByUserNameANDPassword(username, password);
        if (user != null) {
            System.out.println(user);
            return Result.success(user);
        }
        return Result.error("400","请先注册");
    }


}
